home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
235_02
/
ovview.c
< prev
next >
Wrap
Text File
|
1987-06-16
|
24KB
|
696 lines
/* 028 11-Jan-87 ovview.c
Copyright (c) 1987 by Blue Sky Software. All rights reserved.
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "ov.h"
#define H_bar (0xcd)
#define V_bar (179)
#define Vnextch(fh) ((curp < endp) ? *curp++ : vnextch(fh)) /* speed up */
#define Vprevch(fh) ((curp > bufp) ? *--curp : vprevch(fh)) /* buffer access */
extern unsigned char far *curp; /* current char position */
extern unsigned char far *bufp, far *endp; /* buffer begin/end pointers */
static int (*mark_func)(); /* pointer to marker function */
static int nlines; /* # lines displayed on screen */
static unsigned char ascmode; /* true means ascii mode display */
static unsigned char bitmask; /* for 7 or 8 bit display mode */
static int inf; /* handle for file being viewed */
static int margin; /* margin for right/left scrolling */
static long tos; /* top of screen offset in file */
static long markers[5]; /* marker positions */
/* function delcarations created by -Zg option - ALTCALL added
NOTE: anything called by menu routine cannot be ALTCALL */
/*global*/ int view(void);
/*global*/ int view_move(int );
static int view_exit(void), view_down(void), view_up(void), view_next(void);
static int view_prev(void), view_tof(void), view_eof(void);
static int view_right(void), view_left(void), view_set(void), view_goto(void);
static int do_mark(void), setmark(void), gomark(void), ALTCALL view_line(void);
static int ALTCALL fmt_asc_line(char *,int *), ALTCALL fmt_hex_line(char *,int *);
static int view_7bit(void), view_8bit(void), view_asc(void), view_hex(void);
static int ALTCALL align(void);
static int ALTCALL backup(int );
static int ALTCALL peol(void);
static int ALTCALL nsol(void);
static int ALTCALL more2view(void);
static struct key_ent { /* table mapping movement keys to function */
int key;
int (*func)();
} key2func[] = { { DOWN, view_next }, { UP, view_prev }, { PGDN, view_down },
{ PGUP, view_up }, { HOME, view_tof }, { END, view_eof },
{ RIGHT, view_right }, { LEFT, view_left } };
#define NMOVKEYS (8)
extern MENU_STATE curmenu;
extern MENU top_file_menu[], *top_menu;
static char setgo[] = "Set/Goto marker";
static MENU mark_menu[] = {
{ "1", setgo, do_mark, NULL },
{ "2", setgo, do_mark, NULL },
{ "3", setgo, do_mark, NULL },
{ "4", setgo, do_mark, NULL },
{ "5", setgo, do_mark, NULL },
{ NULL, NULL, NULL, NULL }
};
MENU top_view_menu[] = {
{ "Dwn", "Page down in the file", view_down, NULL },
{ "Up", "Page up in the file", view_up, NULL },
{ "Nxt", "Advance one line", view_next, NULL },
{ "Prv", "Backup one line", view_prev, NULL },
{ "TOF", "Goto Top Of File", view_tof, NULL },
{ "EOF", "Goto End Of File", view_eof, NULL },
{ "Rght", "Scroll right 8 characters", view_right, NULL },
{ "Left", "Scroll left 8 characters", view_left, NULL },
{ "Set", "Set marker at current position", view_set, mark_menu },
{ "Goto", "Goto set marker position", view_goto, mark_menu },
{ "Ascii", "View file as ASCII characters", view_asc, NULL },
{ "Hex", "View file in hexadecimal", view_hex, NULL },
{ "7bit", "View low 7 bits of each character", view_7bit, NULL },
{ "8bit", "View all 8 bits of each character", view_8bit, NULL },
{ "Quit", "Return to file display", view_exit, top_file_menu },
{ NULL, NULL, NULL, NULL }
};
extern WINDOW cw;
extern char *cantopen;
extern FILE_ENT files[];
extern unsigned char view_display, restricted;
int ALTCALL vbuf_init(int ); /* declarations for buffer routines */
int ALTCALL vbuf_free(void);
unsigned long ALTCALL vtell(void);
int ALTCALL vseek(int ,long ), ALTCALL vnextch(int ), ALTCALL vprevch(int );
#define view_seek(off) vseek(inf,off)
/******************************************************************************
** V I E W **
*****************************************************************************/
view() { /* view the current file at the terminal */
int i;
register char *fn;
register FILE_ENT *fp;
/* don't try to view file if its empty */
fp = &files[cw.curidx]; /* a couple of quick pointers */
if (fp->size == 0)
show_error(0,8,1,"This file is empty!");
bitmask = 0xff; /* defaults: 8 bit, ascii, left edge */
ascmode = TRUE;
margin = 0;
/* open the file to be viewed, error out if can't open */
if ((inf = open((fn = fname(fp)),O_RDONLY|O_BINARY)) == -1) {
free(fn);
show_error(1,8,3,cantopen,fp->name,": ");
}
savescreen(); /* save current display image */
restricted = TRUE; /* disable special file commands */
view_display = TRUE; /* yes, we are viewing */
for (i = 0; i < 5; i++) /* set markers to TOF */
markers[i] = 0L;
vbuf_init(inf); /* initialize view buffer system */
center_text(FIRST_VROW-1,fn); /* show file name */
free(fn);
view_down(); /* display the first screen of file data */
top_menu = top_view_menu; /* setup the view menu as the main menu */
}
/******************************************************************************
** V I E W _ E X I T **
*****************************************************************************/
static int
view_exit() { /* exit the view display, return to file display */
close(inf); /* close file */
vbuf_free(); /* release memory */
top_menu = top_file_menu; /* restore file menu as main */
restricted = FALSE; /* all commands are enabled */
view_display = FALSE; /* not viewing */
restorescreen(); /* redisplay prior screen image */
}
/******************************************************************************
** V I E W _ D O W N **
*****************************************************************************/
static int
view_down() { /* page down into the view buffer/file */
register int i;
if (!more2view()) /* nothing to do if no more data to view */
return;
nlines = 0; /* no lines displayed yet */
tos = vtell(); /* remember where top of screen is */
/* display up to a screen full of file data, clear the screen as we go */
for (i = 0; i < VIEW_ROWS; i++) {
gotorc(i+FIRST_VROW,0); /* position to line */
if (view_line()) /* display a single line */
nlines++; /* count lines displayed */
}
}
/******************************************************************************
** V I E W _ U P **
*****************************************************************************/
static int
view_up() { /* page up into the view buffer */
long curoff;
/* back two screen's worth, or to the top line in memory and use
view_down() to display the screen - only display if we really
backed up (might be at TOF) */
curoff = vtell(); /* where we were */
view_seek(tos); /* quickly to top of screen */
if (backup(VIEW_ROWS)) /* try to backup another screen */
view_down(); /* display prior screen if backed up */
else
view_seek(curoff); /* must be tof, back to where we were */
}
/******************************************************************************
** V I E W _ N E X T **
**********************************